import {
		BASE_URL
	} from './config.js'

//选择图片
export const chooseImage = (count=9,sizeType=['original', 'compressed'],sourceType=['album', 'camera']) => {


 return new Promise((resolve,reject)=>{
	
	 uni.chooseImage({
	 	count,
	 	sizeType, //可以指定是原图还是压缩图，默认二者都有
	 	sourceType, //从相册选择
	 	success: function(res) {
	 		
			resolve(res.tempFilePaths);
	 		
	 	},fail(error) {
	 		reject(error);
	 	}
	 })
	 
 })

}

//上传文件
export const uploadFile=(filePath)=>{
	
 return	new Promise((resolve,reject)=>{
	 
	 uni.uploadFile({
	 	url: BASE_URL + 'upload/add', //仅为示例，非真实的接口地址
	 	filePath,
	 	name: 'file',
	 	header: {
	 		'Authorization': uni.getStorageSync("token")
	 	},
	 	success: (uploadFileRes) => {
	 					
	 					
	 		let data = JSON.parse(uploadFileRes.data);
	 		// that.imgs.push(data.data);
	 		if(data.errCode===10000){
				
				resolve(data.data);
	 			
	 		}
			else{
				reject(data.errMsg);
			}
	 		
	 	
	 		console.log(data.data);
	 	},
		fail(error) {
				reject(error);
		}
	 });
		
	})
	
}